import { Suspense } from 'react'
import { Navigate, useRoutes, RouteObject as RRouteObject } from 'react-router-dom'
import { RouteObject } from '@/router/interface'
import Login from '@/apps/all-in-one/Login'
import Home from '@/apps/all-in-one/Home'
import Layouts from '@/apps/all-in-one/Layouts'
import BiliBili from '@/apps/bilibili/App'
import BugManager from '@/apps/bug-manager/App'
import WebGames from '@/apps/web-games/App'
import ModuleTest from '@/apps/module-test/App'
import NotFound from '@/apps/all-in-one/NotFound'

import { Outlet } from 'react-router-dom'

// bug-manager-router
import BiliBiliRouter from '@/apps/bilibili/router'
import BugManagerRouter from '@/apps/bug-manager/router/index'
import WebGameRouter from '@/apps/web-games/router'
import ModuleTestRouter from '@/apps/module-test/router/index'
// web-games-router
// import WebGamesRouter from '@/apps/web-games/router/index'

export const rootRouter: RouteObject[] = [
	{
	  path: '/login',
		element: <Login />,
		meta: {
			requireAuth: false,
			title: '登录页',
			key: 'login'
		}
	},
  {
    path: '/aio',
    element: <Layouts />,
    children: [
      {
        path: 'home',
        element: <Home />,
        meta: {
          requireAuth: true,
          title: '首页',
          key: 'home',
        },
			},
			{
				path: 'bilibili',
				element: <BiliBili />,
				meta: {
					requireAuth: true,
					title: 'bilibili',
					key: 'bilibili',
				},
				children: BiliBiliRouter
			},
			{
				path: 'bug-manager',
				element: <BugManager />,
				meta: {
					requireAuth: true,
					title: 'bug-manager',
					key: 'bug-manager',
				},
				children: BugManagerRouter
			},
			{
				path: 'web-games',
				element: <WebGames />,
				meta: {
					requireAuth: true,
					title: 'web-games',
					key: 'web-games',
				},
				children: WebGameRouter
			},
			{
				path: 'module-test',
				element: <ModuleTest />,
				meta: {
					requireAuth: true,
					title: 'module-test',
					key: 'module-test',
				},
				children: ModuleTestRouter
			}
    ]
  },
	{
		path: '/404',
		element: <NotFound />,
		meta: {
			requireAuth: false,
			title: '404',
			key: 'not-found'
		}
	},
	{
		path: '/',
		element: <Navigate to='/login' />,
	},
	{
		path: '*',
		element: <Navigate to='/404' />
	}
]

const Router = () => {
	const routes = useRoutes(rootRouter as RRouteObject[])
	return routes
}

export default Router



// import { Navigate, useRoutes, RouteObject as RRouteObject } from 'react-router-dom'
// import { RouteObject } from '@/router/interface'
// // import Login from '@/views/Login'
// // import Layouts from '@/views/Layouts'
// // import Home from '@/views/Home'
// // import JSDemo from '@/views/JSDemo'
// // import FabricJS from '@/views/JSDemo/FabricJS'
// // import NotFound from '@/views/NotFound'

// // // * 导入所有router
// // const metaRouters = import.meta.globEager('./modules/*.tsx')

// // // * 处理路由
// // export const routerArray: RouteObject[] = []
// // Object.keys(metaRouters).forEach(item => {
// // 	Object.keys(metaRouters[item]).forEach((key: any) => {
// // 		routerArray.push(...metaRouters[item][key])
// // 	})
// // })

// export const rootRouter: RouteObject[] = [
// 	{
// 		path: '/',
// 		element: <Navigate to='/login' />
// 	},
// 	{
// 		path: '/login',
// 		element: <Login />,
// 		meta: {
// 			requireAuth: false,
// 			title: '登录页',
// 			key: 'login'
// 		}
// 	},
// 	{
// 		path: '/aio',
// 		element: <Layouts />,
// 		children: [
// 			{
// 				path: 'home',
// 				element: <Home />,
// 				meta: {
// 					requireAuth: true,
// 					title: '首页',
// 					key: 'home',
// 				},
// 			},
// 			{
// 				path: 'jsdemo',
// 				element: <JSDemo />,
// 				meta: {
// 					requireAuth: true,
// 					title: 'JSDemo',
// 					key: 'jsdemo'
// 				},
// 				children: [
// 					{
// 						path: 'fabricjs',
// 						element: <FabricJS />,
// 						meta: {
// 							requireAuth: true,
// 							title: 'FabricJS',
// 							key: 'fabricjs'
// 						}
// 					}
// 				]
// 			}
// 		]
// 	},
// 	// ...routerArray,
// 	{
// 		path: '/404',
// 		element: <NotFound />,
// 		meta: {
// 			requireAuth: false,
// 			title: '404',
// 			key: 'not-found'
// 		}
// 	},
// 	{
// 		path: '*',
// 		element: <Navigate to='/404' />
// 	}
// ]

// const Router = () => {
// 	const routes = useRoutes(rootRouter as RRouteObject[])
// 	return routes
// }

// export default Router
